package com.example.a2105_ivideo.livedataTest

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.ViewModelProvider
import com.example.a2105_ivideo.R
import com.example.lib_common.utils.LoggerUtils

class LiveDataActivity : AppCompatActivity() {
    private val viewModel:MyViewModel by viewModels()
    private lateinit var viewModel2:MyViewModel
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_live_data)
        viewModel2 = ViewModelProvider(this).get(MyViewModel::class.java)
        //订阅数据
        viewModel.data_.observe(this){
            LoggerUtils.d("LiveDataActivity","更新UI:$it")
        }
    }

    fun loadData(view: View) {
        //网络请求数据
        viewModel.loadDataFromNet()
    }
}